<template>
  <el-table
    :data="tableData"
    style="width: 100%">
    <el-table-column
      label="学员ID"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row._id }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="姓名"
      width="180">
      <template slot-scope="scope">
        {{scope.row.name}}
      </template>
    </el-table-column>
    <el-table-column
      label="分数"
      width="180">
      <template slot-scope="scope">
        {{scope.row.score}}
      </template>
    </el-table-column>
    <el-table-column
      label="性别"
      width="180">
      <template slot-scope="scope">
        {{scope.row.gender}}
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
  import {stuGet,stuDel} from '@/api/stu'
  export default {
    data() {
      return {
        tableData: [{
          _id: 'asdfasdfadsf',
          name: '王小虎',
          score:100,
          gender:1
        }]
      }
    },
    created () {
      stuGet().then(res=>{
        console.log(res);
        this.tableData = res.data.data
      })
    },
    methods: {
      handleEdit(index, row) {
        console.log(index, row);
        this.$router.push({
          path:'/stu/edit',
          query:row
        })
      },
      handleDelete(index, row) {
        console.log(index, row);
        stuDel(row._id).then(res=>{
          console.log(res);
          let {code,msg} = res.data
          if(code==1){
            this.$message({
              type:'success',
              message:msg
            })
            this.tableData.splice(index,1)
          }
        })
      }
    }
  }
</script>

<style lang="less" scoped>

</style>